<template>
	<view style="padding-bottom:125rpx;">
		<view class="header">
			<view class="userInfoBox">
				<view class="infoBoxLeft" @click="goLogin('/subpackages/userInfo/userInfo')">
					<u-avatar :src="userInfo.avatar" size="48"></u-avatar>
					<view>
						<p><text> {{(userInfo.realname || userInfo.username )|| '未登录'}}</text><text
								v-if="userInfo.userType">{{getUserType}}</text>
						</p>
						<p v-if="userInfo.realname || userInfo.username ">编辑个人资料</p>
					</view>
				</view>
				<p @click="goLogin('/subpackages/userInfo/userInfo')" v-if="userInfo.realname || userInfo.username ">
					编辑资料</p>
			</view>
		</view>
		<view class="poster" v-if="!userInfo.userType">
			<view class="">
				<p>
					<image src="/static/images/mine/icon1.png" mode="widthFix"></image>
					<text>你还不是合伙人</text>
				</p>
				<text>开通享合伙人特权</text>
			</view>
			<view class="" @click="goRoute('/subpackages/companyIntro/companyIntro')">
				立即成为
			</view>
		</view>
		<view class="serviceBox">
			<view v-if="[1,2,3].includes(userInfo.userType)" style="background-color:#FFFBF0" class="item"
				@click="judgElet">
				<image src="/static/images/mine/icon2.png" mode="widthFix"></image>
				<text>电量申报</text>
			</view>
			<view style="background-color:#F1F7FF" class="item" @click="goRoute('/subpackages/caseStudy/caseStudy')">
				<image src="/static/images/mine/icon4.png" mode="widthFix"></image>
				<text>案例学习</text>
			</view>
			<view style="background-color: #EBF7EE;" class="item" @click="previewImg(lzImage)">
				<image src="/static/images/mine/icon3.png" mode="widthFix"></image>
				<text>绿电绿证</text>
			</view>
			<view v-if="userInfo.userType==1" style="background-color: #FFF2FE;" class="item"
				@click="goLogin('/subpackages/salesman/salesman')">
				<image src="/static/images/mine/icon5.png" mode="widthFix"></image>
				<text>业务经理入口</text>
			</view>
			<view v-if="userInfo.userType==9" style="background-color: #FFF2FE;" class="item"
				@click="goLogin('/subpackages/contract/contract')">
				<image src="/static/images/mine/icon5.png" mode="widthFix"></image>
				<text>合同管理</text>
			</view>
			<view v-if="userInfo.userType==3" style="background-color: #FFF2FE;" class="item"
				@click="goLogin('/subpackages/powerSales/powerSales')">
				<image src="/static/images/mine/icon5.png" mode="widthFix"></image>
				<text>代理商入口</text>
			</view>
			<view v-if="userInfo.userType==9" style="background-color: rgba(255,223,206,0.5);" class="item"
				@click="goLogin('/subpackages/partner/partner')">
				<image style="transform: scale(0.7);" src="/static/images/home/icon2.png" mode="widthFix"></image>
				<text>合伙人</text>
			</view>
			<view style="background-color: #FFEDEC;" v-if="admin.includes(userInfo.userType)" class="item"
				@click="goLogin('/subpackages/customerFollow/customerFollow',{type:userInfo.userType})">
				<image src="/static/images/mine/icon6.png" mode="widthFix"></image>
				<text>{{userInfo.userType ==9?'审批复核':userInfo.userType==5?'我的复核':'我的审批'}}</text>
			</view>
		</view>
		<u-popup :show="codeShow" mode="center" round="10">
			<view class="codeBox">
				<view class="codeTitle">
					需短信验证身份通过后查看
				</view>
				<!-- 	<view class="inputItem">
					<text>手机号：</text>
					<input v-model="phone" type="number" maxlength="11" />
				</view> -->
				<view class="inputItem">
					<text>验证码：</text>
					<view class="">
						<input v-model="code" type="number" maxlength="10" />
						<text @click="getCode">{{second>0?`${second}秒后重新获取`:'获取验证码'}} </text>
					</view>
				</view>
				<view class="btnItem">
					<text @click="codeShow =false">取消</text>
					<text @click="sumbit">验证</text>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex'
	export default {
		data() {
			return {
				code: '',
				phone: '',
				second: 0,
				launchUserId: '',
				shareShow: true,
				payShow: true,
				codeShow: false,
				lzImage: '',
				partnerList: [],
				admin: [4, 5, 9],
				serviceList: [{
						text: '电量申报',
						icon: '/static/images/mine/icon2.png',
						path: '/subpackages/electricityDeclaration/electricityDeclaration',
						background: '#FFFBF0',
						show: true,
					},
					{
						text: '案例学习',
						icon: '/static/images/mine/icon4.png',
						path: '/subpackages/caseStudy/caseStudy',
						background: '#F1F7FF',
						show: true,
					}
				]
			};
		},
		computed: {
			...mapState({
				userInfo: state => state.userInfo,
			}),
			getUserType() {
				return this.partnerList.find(item => item?.itemValue == this.userInfo.userType)?.itemText
			}

		},
		created() {
			if (this.isLogin()) {
				this.getUserInfo()
				this.dictItemGetlist()
			}
			this.$api.gzLdLzList({
				pages: 1,
				size: 1,
			}).then(res => {
				if (res.data.code == 200) {
					this.lzImage = res.data.result.records[0].url
				}
			})
		},
		onShow() {
			console.log([1, 2, 3])
		},
		methods: {
			...mapActions({
				getUserInfo: 'getUserInfo'
			}),
			lookImg() {
				this.previewImg(this.lzImage)
			},
			dictItemGetlist() {
				this.$api.dictItemGetlist({
					"dictCode": "user_type"
				}).then(res => {
					this.partnerList = res.data.result
				})
			},
			judgElet() {
				 this.goLogin('/subpackages/electricityDeclaration/electricityDeclaration')
				// if (uni.getStorageSync('electTrue')) {
				// 	this.goLogin('/subpackages/electricityDeclaration/electricityDeclaration')
				// } else {
				// 	this.codeShow = true
				// }
			},
			agentIncomeCodeNew() {
				this.$api.agentIncomeCodeNew({}).then(res => {
					if (res.data.code === 0) {
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.second = 60
						let timer = setInterval(() => {
							if (this.second <= 0) {
								clearInterval(timer)
								this.second = 0
							} else {
								this.second--
							}
						}, 1000)
					} else {
						uni.$u.toast(res.data.message);
					}
				})
			},
			sumbit() {
				// if (!uni.$u.test.mobile(this.phone)) return this.showToast('请输入正确的手机号')
				if (!this.code) return this.showToast('请输入验证码')
				uni.showLoading()
				this.$api.verifyVerificationCode({
					smscode: this.code
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.codeShow = false
						this.goRoute('/subpackages/electricityDeclaration/electricityDeclaration')
						uni.setStorageSync('electTrue', true)
					} else {
						this.showToast('验证码错误')
					}
				})
			},
			// 获取验证码
			getCode() {
				if (this.second == 0) {
					this.agentIncomeCodeNew()
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},

		}

	}
</script>
<style>
	page {
		background-color: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
	@import 'mine.scss'
</style>